package com.itic.system.collage.category.service;

import com.itic.appbase.framework.common.constants.DBConst;
import com.sun.star.registry.CannotRegisterImplementationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.itic.appbase.framework.common.service.CrudService;
import com.itic.system.collage.category.persistence.dao.CollageCategoryDao;
import com.itic.system.collage.category.persistence.model.CollageCategory;
import com.itic.system.collage.category.persistence.model.CollageCategoryExample;
import com.itic.system.collage.category.persistence.model.CollageCategoryExample.Criteria;

import java.util.List;


@Service
@Transactional
public class CollageCategoryService
     extends CrudService<CollageCategoryDao,CollageCategory,CollageCategoryExample> {
    @Autowired
    private CollageCategoryDao collageCategoryDao;

    /**
     * 添加拼团类型
     * @param collageId
     * @param spuCategoryId
     * @param categoryName
     * @return
     */
    public CollageCategory addCollageCategory(String collageId,String spuCategoryId,String categoryName){
        CollageCategory category = new CollageCategory();
        category.setCategoryId(spuCategoryId);
        category.setCategoryName(categoryName);
        category.setCollageId(collageId);
        String result = this.add(category);
        if(SUCCESS.equals(result))
            return category;
        else
            return  null;
    }

    /**
     * 修改拼团类型
     * @param category
     * @param spuCategoryId
     * @param categoryName
     * @return
     */
    public String editCollageCategory(CollageCategory category ,String spuCategoryId,String categoryName){
        category.setCategoryId(spuCategoryId);
        category.setCategoryName(categoryName);
        String result = this.edit(category);
        return result;
    }

    /**
     * 根据拼团Id查询拼团类型
     * @param collageId
     * @return
     */
    public List<CollageCategory>  findCollageCategoryByCollageId(String collageId){
        CollageCategoryExample example = new CollageCategoryExample();
        Criteria criteria = example.createCriteria();
        criteria.andIsEffectiveEqualTo(DBConst.TRUE);
        criteria.andCollageIdEqualTo(collageId);
        List<CollageCategory> list = this.list(example);
        return list;
    }
}